package com.guguskins.back.service.impl;

import com.guguskins.back.entity.GuGoods;
import com.guguskins.back.entity.GuInviteLevel;
import com.guguskins.back.entity.vo.PageVo;
import com.guguskins.back.mapper.GuInviteLevelMapper;
import com.guguskins.back.service.GuBoxService;
import com.guguskins.back.service.GuGoodsService;
import com.guguskins.back.service.GuInviteLevelService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author mybatis-plus
 * @since 2021-06-01
 */
@Service
public class GuInviteLevelServiceImpl extends ServiceImpl<GuInviteLevelMapper, GuInviteLevel> implements GuInviteLevelService {
    @Autowired
    private GuInviteLevelMapper inviteLevelMapper;

    @Override
    public PageVo<GuInviteLevel> findByPage(int pageNum, int pageSize, String name) {
        if (pageNum == 1) {

        } else {
            pageNum = (pageNum - 1) * pageSize;
        }
        return new PageVo<>(inviteLevelMapper.findByPage(pageNum, pageSize, name), inviteLevelMapper.findByCount());
    }

    @Override
    public int insert(GuInviteLevel inviteLevel) {
        Integer value=inviteLevelMapper.findByMax();
        BigDecimal count=inviteLevelMapper.findByValue(value);
        if(inviteLevel.getLevelValue()>value&&inviteLevel.getLevelValue()<=value+1){
            if(inviteLevel.getLevelExperience().compareTo(count)>0){
                inviteLevelMapper.insert(inviteLevel);
                return 2;
            }
            return 1;
        }
        return 0;
    }
}
